package com.siyu.model.dispatch.algorithm;

public class MuskingenMethod {
    /*
     * 实例字段和构造器
     */
    private double[] C0;  // 河道不做分段，一个参数
    private double[] C1;  // 河道不做分段，一个参数
    private double[] C2;  // 河道不做分段，一个参数

    public MuskingenMethod() {
        this.C0 = new double[]{0.2};  // 河道不做分段，一个参数
        this.C1 = new double[]{0.6};  // 河道不做分段，一个参数
        this.C2 = new double[]{0.2};  // 河道不做分段，一个参数
    }

    public double[] msjg(double[] Q_up) {
        int RiverLength = C0.length;//河段数，分段马斯京根演算时里面的河段数
        int Q_up_length = Q_up.length;//入流过程的时段数
        double[][] Result = new double[Q_up_length][C0.length + 1];//各个时间段中各个河段的入流与出流
        double[] Q_down = new double[Q_up_length];
        double[][] c = new double[3][RiverLength];//第一行为c0,第二行c1，第三行c2

        for (int i = 0; i < RiverLength; i++) {
            c[0][i] = C0[i];
            c[1][i] = C1[i];
            c[2][i] = C2[i];
        }

        //进行循环计算
        for (int i = 0; i < Q_up_length; i++) {
            for (int j = 0; j < C0.length + 1; j++) {
                if (i == 0) {
                    Result[i][j] = Q_up[i];
                } else {
                    if (j == 0) {
                        Result[i][j] = Q_up[i];
                    } else {
                        Result[i][j] = c[0][j - 1] * Q_up[i] + c[1][j - 1] * Q_up[i - 1] + c[2][j - 1] * Result[i - 1][j - 1];
                    }
                }
            }
        }
        for (int i = 0; i < Q_up.length; i++) {
            Q_down[i] = Result[i][C0.length];
        }
        return Q_down;
    }
}
